import Vue from "vue";
import ViewUI, {locale} from "view-design";
// import iViewPro from 'public/3thComponents/iview-pro/iview-pro.min.js';
import iViewPro from 'public/3thComponents/iview-pro/iview-pro.min.js';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css'
// import 'public/3thComponents/iview-pro/iview-pro.css';
import 'public/3thComponents/iview-pro/iview-pro.css';
import 'public/styles/index.less';
import 'view-design/dist/styles/iview.css';
import 'public/3thComponents/iviewAdmin'
// import TableImportExport from 'public/3thComponents/iview-pro/table-import-export.min';
import TableImportExport from 'public/3thComponents/iview-pro/table-import-export.min';
import formCreate from '@form-create/iview4'
import VConsole from 'vconsole'
import dataV from '@jiaminghi/data-view'

import '../styles/index.less';
import '../styles/tailwind.css';

import App from '../App'
import tools from 'public/tools/index';
Vue.prototype.tools=tools;
import store from '@/store';
import globalMixin from 'public/mixins/globalMixin';
import { getRouter } from "../router/index";
import { getMenu } from "../menu/";
import 'public/components';
// import 'public/starLib';
// import 'public/reportLib';

import initialI18n from 'public/i18n';
import Languages from 'public/i18n/locale';
import plugins from 'public/plugins';
import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
import VueClipboard from 'vue-clipboard2'
import 'codemirror/lib/codemirror.css'

VueClipboard.config.autoSetContainer = true // add this line
Vue.use(VueClipboard)

Vue.use(ElementUI);
Vue.use(iViewPro);
// console.log("file: index.js:30  iViewPro:", iViewPro)
Vue.use(TableImportExport);
Vue.mixin(globalMixin);
Vue.use(ViewUI);
Vue.use(formCreate);
Vue.use(plugins);
Vue.use(mavonEditor);
Vue.use(dataV);

window.tools = tools

if (window.URL) {
    let locHref = new URL(location.href)
    if (locHref.searchParams.get('debug')) {
        let vConsole = new VConsole();
    }
}
export async function initial(fn) {
    let setting=require('../setting').default;
    let curLanguage = setting.i18n.default
    let i18n=initialI18n(curLanguage);
    locale(Languages[curLanguage])
    let api=require('public/service/scenario').api;
    // let sysSetting = localStorage.getItem('sys_setting')
    if (location.href.includes('/login')) {
        tools.cookies.remove('token')
    }
    let sysSetting = await store.dispatch('loadProject', {api, isUpdate: true})
    if (sysSetting && sysSetting.curItem) {
        setting = Object.assign(setting, sysSetting.curItem)
    }
    
    store.commit('initial',{tools,setting});
    
    store.commit('setApi',api);
    Vue.prototype.$api=api;
    let modelObject=require('public/model/starModel').default;
    Vue.prototype.$modelObject=modelObject;

    // let models = await api.getAllModelInfo(); // getAllModel getAllModelInfo
    // store.dispatch('admin/model/setAll',models)
    await store.dispatch('admin/model/loadModelInfo')
    store.commit('admin/layout/setCurrentAccount',api);
    // store.dispatch('admin/model/loadGlobalOption')

    let menu=getMenu();
    store.commit('admin/layout/setMenu',menu);
    let router=getRouter(setting,store);
    /**eventBus*/
    let eventBus=new Vue();
    window.EventBus=eventBus;
    Vue.prototype.$EventBus=eventBus;

    window.store=store;
    /**return*/
    return {router,store,i18n,App}
}
